<?php
declare (strict_types = 1);

namespace app\mobile\controller;
use think\facade\Request;
use think\facade\Db;
class Index extends \app\mobile\controller\Base
{



  public function launcher()
  {
    $r['page'] = $this->sysbase['launcher'];
    return $this->doSuccess('ok',$r);
    # code...
  }
  public function types()
  {
    //顶部分类
    $types = array();
    $type = array();
    $type['name'] = '首页';
    $type['cid'] = 1;
    $types[] = $type;

    $type = array();
    $type['name'] = '电脑';
    $type['cid'] = 1;
    $types[] = $type;

    $type = array();
    $type['name'] = '运动';
    $type['cid'] = 1;
    $types[] = $type;

    $type = array();
    $type['name'] = '手机';
    $type['cid'] = 1;
    $types[] = $type;

    $type = array();
    $type['name'] = '男装';
    $type['cid'] = 1;
    $types[] = $type;

    $type = array();
    $type['name'] = '女装';
    $type['cid'] = 1;
    $types[] = $type;

    $type = array();
    $type['name'] = '鞋包';
    $type['cid'] = 1;
    $types[] = $type;

    $type = array();
    $type['name'] = '食品';
    $type['cid'] = 1;
    $types[] = $type;

    $type = array();
    $type['name'] = '母婴';
    $type['cid'] = 1;
    $types[] = $type;

    return $this->doSuccess('ok',$types);
  }

  public function notice()
  {
    $list = [];
    $v['title'] = ' 新版使用说明';
    $v['url'] = '121';
    $v['opentype'] = 'navigate';
    $list[] = $v;
    // $v['title'] = ' 精品 IT 课程中心';
    // $v['url'] = '121';
    // $v['opentype'] = 'switchTab';
    // $list[] = $v;
    return $this->doSuccess('ok',$list);
    # code...
  }

  public function swipers()
  {
    $list = [];
    return $this->doSuccess('ok',$list);
    $v['title'] = ' 新版使用说明';
    $v['url'] = '121';
    $v['img'] = 'https://graceui.oss-cn-beijing.aliyuncs.com/swiperimgs/1.png';
    $v['opentype'] = 'navigate';
    $list[] = $v;
    $v['title'] = ' 新版使用说明';
    $v['url'] = '121';
    $v['img'] = 'https://graceui.oss-cn-beijing.aliyuncs.com/swiperimgs/2.png';
    $v['opentype'] = 'navigate';
    $list[] = $v;
    // $v['title'] = ' 精品 IT 课程中心';
    // $v['url'] = '121';
    // $v['opentype'] = 'switchTab';
    // $list[] = $v;
    return $this->doSuccess('ok',$list);
  }

  //授权备案回调
      # code...
  public function relationBack()
  {
    $data = input('callback_data');
    $uid = input('note');
    $data = json_decode($data,true);
    if ($data['code'] != 200) {
      return $data['msg'];
    }
    $account_name = $data['data']['account_name'];
    $relation_id = $data['data']['relation_id'];
    $ck = Db::name('user_relation')->where('relation_id',$relation_id)->find();
    if (!$ck) {
      $v = array();
      $v['account_name'] = $account_name;
      $v['note'] = $uid;
      $v['uid'] = $uid;
      $v['create_date'] = date('Y-m-d H:i:s');
      Db::name('user_relation')->insert($v);
    }
    Db::name('user')->where('id',$uid)->update([
      'relation_id'=>$relation_id,
    ]);

    return '授权成功，请返回微信。';
  }

}
